{include file="common/head"}
<title>编辑</title>

  <link rel="stylesheet"    href="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.24.2/jodit.es2018.min.css"/>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.24.2/jodit.es2018.min.js"></script>   
</head>
<body>
    <div class="container p-3 my-3 " style="max-width: 600px;">
    <h2>商品新增</h2>

    <form method="post" action="/index.php/goods/goods_add" enctype="multipart/form-data">
       <div class="mb-3 row">
        <div class="col-2">
          <lable for="fid" class="form-label">商品分类: </label>
        </div>
        <div class="col-10">
          <select id="cat_id" name="cat_id" class="form-control">
              {foreach $cats as $k=>$v}
                <option value="{$k}" style="font-weight: bold" >
                    {if $v['deepth']==1}
                        ├─
                    {elseif $v['deepth']==2}
                        &nbsp;&nbsp;&nbsp;&nbsp;├─
                    {elseif $v['deepth']==3}
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├─
                    {/if}

                {$v['name']}</option>
              {/foreach}
          </select>
        </div>
      </div>

      <div class="mb-3 row">
        <div class="col-2"><label for="name" class="form-label">名称:</label></div>
        <div class="col-10"><input type="text" class="form-control" id="name" name="name" value="" placeholder="name"/></div>
      </div>
  
      <div class="mb-3 row">
        <div class="col-2">
          <label for="desc" class="form-label">说明:</label>
        </div>
        <div class="col-10">
          <input type="text" class="form-control" id="desc" name="desc" value="" placeholder="Description" />
        </div>
      </div>      

     <div class="mb-3 row">
        <div class="col">
        <label for="price" class="form-label">起步价:</label>
        <input type="number" class="form-control" id="price" name="price" value="" placeholder="Price" />          
        </div>      
        <div class="col" style="display: none;">
        <label for="discount" class="form-label">折扣(0.1-5.0):</label>
        <input type="number" class="form-control" id="discount" name="discount" value="1"  min="0.1" max="5.0" step="0.1" />
        </div>
        <div class="col">
          <label for="price1" class="form-label">最高价:</label>
          <input type="number" class="form-control" id="price1" name="price1" value=""  />  
        </div>
      </div>

      <div class="mb-3 row">
        <div class="col-2"><label for="file" class="form-label">上传图片:</label></div>
        <div class="col-10">
          <input id="file1" type="file"  name="file1" />
          <input id="file2" type="file"  name="file2" />
          <input id="file3" type="file"  name="file3" />
          <input id="file4" type="file"  name="file4" />

        </div>
      </div>
      
      <div class="mb-3 row">
        <div class="col-2"><label for="title" class="form-label">网络图<br/>(请注意：只粘贴网络图片地址，多个图片用英文逗号分隔图片):</label></div>
        <div class="col-10">
          <textarea id="other_imgs" name="other_imgs" class="form-control" style="height: 140px;"></textarea>
        </div>
      </div>

      <div class="mb-3 row">
        <label for="title" class="form-label">详细介绍:</label>
        <div class="col"><textarea id="content" name="content" class="form-control"></textarea></div>
      </div>

      <div class="mb-3">
        <label for="status" class="form-label">是否启用:</label>
          <input type="radio" class="form-check-input" id="radio1" name="status" value="1" checked /> 
          <label class="form-check-label" for="radio1">上架</label>
          <input type="radio" class="form-check-input" id="radio2" name="status" value="2" />
          <label class="form-check-label" for="radio2">下架</label>
       </div>

      <button  type="button" class="btn btn-primary" onclick="doSave()">保存(Save)</button>
    </form>
    </div>

  <script type="text/javascript">
    function doSave(){
      if(!$("#name").val() || !$("#price").val() || !$("#discount").val()){
        layer.msg("别瞎闹！",function(){});
        $("#discount").val(1);
        return false;
      }
      $('form').submit();
    }

    var editor = Jodit.make('#content',{
      toolbarButtonSize: 'small',
      language: 'zh_cn',
    });

    $(document).ready(function(){

      $("#discount,#price").on('blur',function(){
        var price = $("#price").val();
        var ds = $("#discount").val();

        if(isNaN(ds) || ds<0.1 || ds>1){
          layer.msg('折扣错误！');
          $("#discount").val(1);
        }else{
          $("#price1").val(($("#price").val()*ds).toFixed(2));
        }
      })
    })
  </script>


</body>
</html>
